package com.atguigu.study;

import com.atguigu.study.entity.User;
import com.atguigu.study.mapper.UserMapper;
import com.atguigu.study.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import io.minio.errors.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

@SpringBootTest
public class MyTest2 {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserService userService;

    @Test
    public void test01() {
        System.out.println(userMapper.selectList(null));
    }

    @Test
    public void test02() {
        //逻辑删除记录
        //sql语句
        //==>  Preparing: UPDATE user SET deleted=1 WHERE id=? AND deleted=0
        //==> Parameters: 1(Integer)
        //<==    Updates: 1
        userMapper.deleteById(1);
    }

    @Test
    public void test03() {
        userMapper.insert(new User(null, "Clifu2", 28, "Clifu@baomidou.com"));
    }

    @Test
    public void test04() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient minioClient = MinioClient.builder()
                .endpoint("http://192.168.100.101:9000")
                .credentials("root", "12345678")
                .build();
        BucketExistsArgs builder = BucketExistsArgs
                .builder()
                .bucket("lease-bucket").build();
        boolean b = minioClient.bucketExists(builder);
        System.out.println(b);
    }

    @Test
    public void test05() throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient minioClient = MinioClient.builder()
                .endpoint("http://192.168.100.101:9000")
                .credentials("root", "12345678")
                .build();
        UploadObjectArgs objectArgs = UploadObjectArgs
                .builder()
                .bucket("lease-bucket")
                .object("test.jpg")
                .filename("E:\\360MoveData\\Users\\Administrator\\Desktop\\test.jpg")
                .build();
        minioClient.uploadObject(objectArgs);
    }

}
